package com.itmake.webflux.security.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * security 工具
 *
 * @author Amjacks
 * @since 2023/08/10
 */
public class SecurityUtil {

    private SecurityUtil() {}

    /**
     * 生成 BCryptPasswordEncoder 密码
     *
     * @param password 密码
     * @return 加密字符串
     */
    public static String encryptPassword(String password) {
        return new BCryptPasswordEncoder().encode(password);
    }

    /**
     * 判断密码是否相同
     *
     * @param rawPassword     真实密码
     * @param encodedPassword 加密后字符
     * @return 结果
     */
    public static boolean matchesPassword(String rawPassword, String encodedPassword) {
        return new BCryptPasswordEncoder().matches(rawPassword, encodedPassword);
    }
}
